<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑投标信息</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="bidtype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目所在地</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">招标方</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhaoname" id="zhaoname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">招标方联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhaotel" id="zhaotel" placeholder="请输入"  clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">预计合同金额(万元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="yufee" name="yufee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput6">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目所属单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=chanid&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="chanid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=chanid&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="chanid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目属性</label>
                        <div class="layui-input-block ">
                            <select id="business" name="business" lay-filter="business">
                                <option value="">请选择</option>
                                <option value="1">自营</option>
                                <option value="2">联营</option>
                            </select>
                            <p class="error" id="business_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">经营备案人</label>
                        <div class="layui-input-block">
                            <input type="text" name="jingbeier" id="jingbeier" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">信息来源</label>
                        <div class="layui-input-block">
                            <input type="text" name="xinlai" id="xinlai" placeholder="请输入"  clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>




            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">报名截止时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt_bao" id="enddt_bao" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>投标截止时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt_tou" id="enddt_tou" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开标时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="kaidt" id="kaidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>投标负责人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=touer&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="touer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=touer&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="touer_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>投标单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=touunit&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="touunit"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=touunit&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="touunit_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">参投说明</label>
                        <div class="layui-input-block">
                            <input type="text" name="toushuo" id="toushuo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div id="business_lian" class="layui-hide">
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>联营单位</label>
                            <div class="layui-input-block">
                                <input type="text" readonly name="lianunit" class="layui-input lianunit" onclick="openPage('../public/choose_dealcom.php?dom=lianunit','80%','80%')">
                                <div class="choose_div" id="lianunit" key="1"></div>
                                <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=lianunit','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>是否收费</label>
                            <div class="layui-input-block">
                                <select id="isfei" name="isfei" lay-filter="isfei">
                                    <option value="">请选择</option>
                                    <option value="是">是</option>
                                    <option value="否">否</option>
                                </select>
                                <p class="error" id="isfei_error" style="margin: 0;"></p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">费用收取说明</label>
                            <div class="layui-input-block">
                                <input type="text" name="feishuo" id="feishuo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">项目概况</label>
                        <div class="layui-input-block">
                            <textarea id="gai" name="gai" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            enddt_tou: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            enddt_tou: {required: "请选择"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_bid_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $('#name').val(data.name);
                $('#number').val(data.number);
                $('#addr').val(data.addr);
                $('#zhaoname').val(data.zhaoname);
                $('#zhaotel').val(data.zhaotel);
                $('#yufee').val(data.yufee);
                $('#business').val(data.business);
                $('#jingbeier').val(data.jingbeier);
                $('#xinlai').val(data.xinlai);
                $('#enddt_bao').val(data.enddt_bao);
                $('#enddt_tou').val(data.enddt_tou);
                $('#toushuo').val(data.toushuo);
                $('#kaidt').val(data.kaidt);
                $('#isfei').val(data.isfei);
                $('#feishuo').val(data.feishuo);
                $('#gai').val(data.gai);
                $('#explain').val(data.explain);



                if(data.touer_info.length > 0){
                    tan_tags_init('#touer', data.touer_info);
                }
                if(data.chanid_info.length > 0){
                    tan_tags_init('#chanid', data.chanid_info);
                }
                if(data.touunit_info.length > 0){
                    tan_tags_init('#touunit', data.touunit_info);
                }

                set_choose_btn('lianunit',data.lianunit,data.lianunit);


                if(data.business == 2){
                    $("#business_lian").removeClass('layui-hide');
                }else{
                    $("#business_lian").addClass('layui-hide');
                }

                $("#areas").val(data.areas);
                load_areas('areas', res.data.areas, 3);
                xmselect_dan('bidtype', res.data.bidtype, data.bidtype);
                xmselect_dan('zhaotype', res.data.zhaotype, data.zhaotype);


                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(business)', function(data){
            if(data.value == 2){
                $("#business_lian").removeClass('layui-hide');
            }else{
                $("#business_lian").addClass('layui-hide');
            }

            if(data.value == ''){
                $('#business_error').show().text('请选择');
                $('#business_error').parent().find('input').addClass('select_error');
            }else{
                $('#business_error').hide();
                $('#business_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(isfei)', function(data){
            if(data.value == ''){
                $('#isfei_error').show().text('请选择');
                $('#isfei_error').parent().find('input').addClass('select_error');
            }else{
                $('#isfei_error').hide();
                $('#isfei_error').parent().find('input').removeClass('select_error');
            }
        });


        form.on('submit(add)', function(data){
            data.field.touer = tan_tags_getvalue("#touer", 'user');
            data.field.chanid = tan_tags_getvalue("#chanid", 'dept');
            data.field.touunit = tan_tags_getvalue("#touunit", 'dept');
            data.field.lianunit = get_choose_val('lianunit');


            var validRes = $("#commentForm").valid();

            if(!data.field.chanid){
                $("#chanid").parents('.tanxian').addClass('tanerror');
                $('#chanid_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#chanid").parents('.tanxian').removeClass('tanerror');
                $('#chanid_tanerror').text('');
            }

            if(!data.field.touer){
                $("#touer").parents('.tanxian').addClass('tanerror');
                $('#touer_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#touer").parents('.tanxian').removeClass('tanerror');
                $('#touer_tanerror').text('');
            }

            if(!data.field.touunit){
                $("#touunit").parents('.tanxian').addClass('tanerror');
                $('#touunit_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#touunit").parents('.tanxian').removeClass('tanerror');
                $('#touunit_tanerror').text('');
            }

            if(data.field.business == ''){
                $('#business_error').show().text('请选择');
                $('#business_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#business_error').hide();
                $('#business_error').parent().find('input').removeClass('select_error');
            }

            if(data.field.business == 2){
                formValid('lianunit');
                if(data.field.lianunit == undefined || !data.field.lianunit){
                    validRes = false;
                }

                if(data.field.isfei == ''){
                    $('#isfei_error').show().text('请选择');
                    $('#isfei_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#isfei_error').hide();
                    $('#isfei_error').parent().find('input').removeClass('select_error');
                }
            }
            if(!validRes){return false;}

            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_bid_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
